import java.awt.event.*;
import javax.swing.*;

public class ServeCustomerButton extends JButton{
	//	Local Variables
	private JFrame _parentFrame;
	private StoreLogic _logic;
	private QueuePanel _queueP;
	
	public ServeCustomerButton(JFrame aParentFrame, StoreLogic alogic, QueuePanel aQueueP)
	{
		super("Serve Customer in selected queue");
		_parentFrame = aParentFrame;
		_logic = alogic;
		_queueP = aQueueP;
		this.addActionListener(new ServeListener());
	}
	
	private class ServeListener implements ActionListener 
	{
		public void actionPerformed(ActionEvent e) 
		{	
			if (!_logic.getLineStatus(_queueP.getSelectedQueue()))
			{	
				JOptionPane.showMessageDialog(_parentFrame, "This line is closed.","Error", 1);
			}
			else if(_logic.getInLine(_queueP.getSelectedQueue()).getSize() == 0)
			{
				JOptionPane.showMessageDialog(_parentFrame, "There are no customers in this line.","Error", 1);
			}
			else
			{
				CheckOutFrame _NewCheckOutFrame = new CheckOutFrame(_parentFrame, _logic.getFirstPersonInLine(_queueP.getSelectedQueue()));
				_logic.serveCustomer(_queueP.getSelectedQueue());
			}
		}
	}
}
